Skip to content

Detect Cloudflare WAF block pages and show a helpful error message in stead of "Received a malformed response from the API"#13574

Merged
dario-piotrowicz merged 5 commits intomainfrom
dario/13312/malformed-response-block-page
Apr 21, 2026
Merged

Detect Cloudflare WAF block pages and show a helpful error message in stead of "Received a malformed response from the API"#13574
dario-piotrowicz merged 5 commits intomainfrom
dario/13312/malformed-response-block-page

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Apr 16, 2026

Fixes #13312

When the Cloudflare WAF blocks an API request, the response is an HTML page rather than JSON. Previously, this caused a confusing "Received a malformed response from the API" error with a truncated HTML snippet. Wrangler now detects WAF block pages and displays a clear error message explaining that the request was blocked by the firewall, along with the Cloudflare Ray ID (when available) for use in support tickets.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: UX improvement

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 16, 2026

🦋 Changeset detected

Latest commit: 0b90fb2

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

Changeset Review

File Reviewed: .changeset/detect-waf-block-response.md

Criterion Status Notes
Version Type patch is appropriate for this bug fix (improving error message clarity)
Changelog Quality Clear description of the problem (confusing "malformed response" error) and solution (helpful WAF block detection with Ray ID)
Markdown Headers No h1/h2/h3 headers found
Analytics No analytics collection mentioned
Dependabot Not a dependabot changeset
Experimental Features Not an experimental feature

✅ All changesets look good

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 16, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13574

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13574

miniflare

npm i https://pkg.pr.new/miniflare@13574

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13574

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13574

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13574

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13574

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13574

wrangler

npm i https://pkg.pr.new/wrangler@13574

commit: 0b90fb2

@dario-piotrowicz dario-piotrowicz force-pushed the dario/13312/malformed-response-block-page branch 3 times, most recently from 5fdb36a to e916798 Compare April 17, 2026 12:10
@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review April 17, 2026 12:11
@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team April 17, 2026 12:11
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 17, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Comment thread packages/wrangler/src/cfetch/internal.ts Outdated
Comment thread packages/wrangler/src/cfetch/internal.ts Outdated
@WalshyDev
Copy link
Copy Markdown
Member

also for any and all html instead of json it'd be good to get a ray id even aside WAF, we can always use that to dig into logs :)

…stead of "Received a malformed response from the API"
@dario-piotrowicz dario-piotrowicz force-pushed the dario/13312/malformed-response-block-page branch from e916798 to 9eb90e1 Compare April 20, 2026 23:13
@dario-piotrowicz
Copy link
Copy Markdown
Member Author

also for any and all html instead of json it'd be good to get a ray id even aside WAF, we can always use that to dig into logs :)

Done! 🫡 😄 11cbf00

Comment thread .changeset/malformed-response-ray-id.md Outdated
Copy link
Copy Markdown
Contributor

@workers-devprod workers-devprod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Apr 21, 2026
@dario-piotrowicz dario-piotrowicz merged commit d5e3c57 into main Apr 21, 2026
61 of 63 checks passed
@dario-piotrowicz dario-piotrowicz deleted the dario/13312/malformed-response-block-page branch April 21, 2026 15:10
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Wrangler Deploy Error: Received a malformed response from the API

4 participants